package com.mpgame.core.effect;

import com.fasterxml.jackson.databind.JsonNode;
import com.mpgame.core.model.Monster;

public abstract class Effect {
    private double probability = 1.0;
    private String identifier;
    public void setIdentifier(String identifier) {this.identifier = identifier;}
    public String getIdentifier(){return this.identifier;}
    public void setProbability(double probability){this.probability = probability;}
    /** 专属解析json方法 */
    protected abstract void innerParseJson(JsonNode params);
    /** 若生效，会发生什么 */
    protected abstract void take(Monster target);

    /** 解析json并将数据应用到本对象(自动提取probability属性) */
    public void parseJson(JsonNode params){
        if(params.has("probability")) setProbability(params.get("probability").asDouble());
        innerParseJson(params);
    }
    /** 对外开放应用到对象上（受概率影响） */
    public void apply(Monster target){
        if(Math.random() < probability){
            take(target);
        }
    }
}
